/**
 * This class allows a comparing of two abstract gaming situations/positions
 */
package AIEngine;

import java.util.Comparator;

public class NodeComparator implements Comparator {

    private boolean sortby = true; //sort sequence (true = in ascending order, false=downward )

    /**
     * Takes the commited objects as a objects off classtype of node and compares them with each other
     * according to sortby
     *
     * @param n1 First node
     * @param n2 Second node
     * @return -1 if n1<n2, 0 if n1==n2 and 1 if n1>n2
     */
    public int compare(Object n1, Object n2) {

        if (sortby) {
            if (((Node) n1).getValue() < ((Node) n2).getValue()) {
                return -1;
            }

            if (((Node) n1).getValue() > ((Node) n2).getValue()) {
                return 1;
            }

            return 0;
        } else {
            if (((Node) n1).getValue() < ((Node) n2).getValue()) {
                return 1;
            }

            if (((Node) n1).getValue() > ((Node) n2).getValue()) {
                return -1;
            }

            return 0;
        }

    }

    /**
     * Setter for sortby
     * see sortby
     * @param sortby
     */
    public void setSortBy(boolean sortby) {
        this.sortby = sortby;
    }
} 

